import playerlib

from wcs.libs.items import items
from wcs.libs.players import players

itemName = 'Helmet of Clear View'
item = items.addItem(itemName)
item.setGroup("defense")
item.setCost(4000)
item.setDescription("This helmet reduces the flashbang effect by 50%%")
item.setMaxCount(1)
item.aliveToUse = True
        
def player_blind(event_var):
    """
    Executed when a player is blinded by a flashbang. If the user has this item,
    ensure that their flash alpha is reduced by 50%.
    """
    userid = event_var["userid"]
    player = players[userid]
    if player.getItem(itemName).count:
        playerlibObject = playerlib.getPlayer(userid)
        flashAlpha, flashDuration = playerlibObject.getFlash()
        playerlibObject.flash(flashAlpha / 2.0, flashDuration)
